這篇想要來寫鏈表~因為一開始看到不知道是甚麼
原來是鏈表LIST
感覺很專業~那就來了解一下
先聲明裏面有四個整數:
using System;
using System.Collections.Generic;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
List <int> userAgeList = new List <int> { 11,21,31,41};
}
}
}
當要選第一個就是0時,
using System;
using System.Collections.Generic;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
List <int> userAgeList = new List <int> { 11,21,31,41};
userAgeList[0];
}
}
}
當要第2個位置加入51
using System;
using System.Collections.Generic;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
List <int> userAgeList = new List <int> { 11,21,31,41};
userAgeList.Insert(2,51);
Console.WriteLine(userAgeList);
}
}
}
把裡面有51的取出來
using System;
using System.Collections.Generic;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
List <int> userAgeList = new List <int> { 11,21,31,41};
userAgeList.Insert(2,51);
userAgeList.Remove(51);
Console.WriteLine(userAgeList);
}
}
}
把裡面有第3個位置取出來
using System;
using System.Collections.Generic;
namespace HelloWorld2
{
class Program
{
public static void Main(string[] args)
{
List <int> userAgeList = new List <int> { 11,21,31,41};
userAgeList.Insert(2,51);
userAgeList.RemoveAt(2);
Console.WriteLine(userAgeList);
}
}
}
DEAR ALL 我們明天見